//; ---------------------------------------------------------------------------
//; Object 1C - scenery (GHZ bridge stump, SLZ lava thrower)
//; ---------------------------------------------------------------------------

#include "scenery.h"

#include "../sprite.h"
#include "../objectsystemNEWER.h"

static object *obj;

//EXTERN DEFINITIONS HERE
extern byte *Map_Bri[3];

//; ---------------------------------------------------------------------------
//; Animation script - (OBJECT)
//; ---------------------------------------------------------------------------

//; ---------------------------------------------------------------------------
//; Sprite mappings - SLZ lava thrower
//; ---------------------------------------------------------------------------
byte byte_8858[6] = { 1,
		   0xF0, 7, 0, 0, 0xF8
};
byte *Map_Scen[1] = { byte_8858 };

//; ===========================================================================
//; ---------------------------------------------------------------------------
//; Variables for	object $1C are stored in an array
//; ---------------------------------------------------------------------------

struct scen_val
{
    byte** map;
    word vram;
    byte frame;
    byte actionwidth;
    byte priority;
    byte coltype;
};

scen_val Scen_Values[4] = { { Map_Scen, 0x44D8, 0, 8, 2, 0 }, 
                            { Map_Scen, 0x44D8, 0, 8, 2, 0 }, 
                            { Map_Scen, 0x44D8, 0, 8, 2, 0 }, 
                         { Map_Bri,  0x438E, 1, 0x10, 1, 0 }
}; 
//==========

void (*Scen_Index[2])() = { Scen_Main, Scen_ChkDel };

//OBJECT:					; XREF: Obj_Index
void Scenery(object *_obj)
{
    obj = _obj;

    //moveq	#0,d0
    //move.b	obRoutine(a0),d0
    byte routine = obj->Routine/2;

    //move.w	Ring_Index(pc,d0.w),d1
    //jmp	Ring_Index(pc,d1.w)
    (*Scen_Index[routine])();
}

//; ===========================================================================

//OBJECT_Main:	; Routine 0
void Scen_Main()
{
    //Scen_Main:	; Routine 0
    //addq.b	#2,obRoutine(a0)
    obj->Routine = obj->Routine + 2;

    //moveq	#0,d0
    //move.b	obSubtype(a0),d0 ; copy object subtype to d0
    //mulu.w	#$A,d0		; multiply by $A
    word index = obj->Subtype;   // * 10;

    //lea	Scen_Values(pc,d0.w),a1
   scen_val scenVars = Scen_Values[index];

   //move.l	(a1)+,obMap(a0)
   obj->Map = scenVars.map;

   //move.w	(a1)+,obGfx(a0)
   obj->Gfx = scenVars.vram;

   //ori.b	#4,obRender(a0)
   obj->Render = obj->Render | 4;

   //move.b	(a1)+,obFrame(a0)
   obj->Frame = scenVars.frame;

   //move.b	(a1)+,obActWid(a0)
   obj->ActionWidth = scenVars.actionwidth;

   //move.b	(a1)+,obPriority(a0)
   obj->Priority = scenVars.priority;

   //move.b	(a1)+,obColType(a0)
   obj->ColType = scenVars.coltype;

   Scen_ChkDel();
}

//Scen_ChkDel:	; Routine 2
void Scen_ChkDel()
{
    //out_of_range	DeleteObject
    if (out_of_range(obj)) { DeleteObject(obj); }

    //bra.w	DisplaySprite
    DisplaySprite(obj);

}



